<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑列车</title>
    <script type="text/javascript">
      Ext.onReady(function(){

        var dateDateField = new Ext.form.DateField({
          fieldLabel: '信息更新日期',
          name: 'date',
          format: 'Y-m-d',                    //格式化日期
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "日期必须选择",
          readOnly: true,
          emptyText: '请选择日期...',
          anchor: '95%'                    //在容器中的时候，自动按照容器百分比进行调整，会覆盖宽度的属性
        });

        var trainTypeStore = new Ext.data.ArrayStore({
          fields: [{name:'trainType',type:'int'},'text'],
          data : trainTypeArray
        });
        var trainType = new Ext.form.ComboBox({
          fieldLabel: '动车类型',
          store: trainTypeStore,
          valueField:'trainType',
          hiddenName:'trainType',
          displayField:'text',
          typeAhead: true,
          mode: 'local',
          triggerAction: 'all',
          selectOnFocus:true,
          name:'trainType',
          emptyText:'请选择动车类型...',
          allowBlank: false,
          anchor: '95%'
        });

        var trainId=<%=params[:id]%>
        var editTrainForm=new Ext.form.FormPanel({
          labelAlign: 'top',
          url:'/train/update',
          buttonAlign:'center',
          autoHeight:true,
          bodyStyle: 'padding:5px',
          labelWidth:100,
          frame: true,
          reader:new Ext.data.JsonReader({
          },[
            {name:'id'},
            {name:'sn'},
            {name:'last_length'},
            {name:'now_length'},
            {name:'all_length'},
            {name:'xx_length'},
            {name:'ts_length'},
            {name:'two_level_fix_length'},
            {name:'fourx_length'},
            {name:'threex_length'},
            {name:'date',type:'date',dateFormat: 'Y/m/d'},
            {name:'trainType',mapping:'train_type',type:'int'}
          ]
        ),
          items:[{
              xtype:'hidden',
              name:'id',
              value:''
            },
            {
              layout:'column',
              items:[
                {
                  columnWidth:.5,
                  layout:'form',
                  items:[{
                      xtype:'fieldset',
                      title:'日常走行',
                      width:150,
                      buttonAlign: 'center',
                      autoHeight:true,
                      items:[{
                          xtype:'textfield',
                          fieldLabel: '列车编号',
                          name: 'sn',
                          allowBlank:false,
                          anchor:'95%'
                        },
                        dateDateField,
                        trainType,
                        {
                          xtype:'numberfield',
                          fieldLabel: '上次走行公里',
                          name: 'last_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'numberfield',
                          fieldLabel: '本次走行公里',
                          name: 'now_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'numberfield',
                          fieldLabel: '总走行公里数',
                          name: 'all_length',
                          readOnly:false,
                          anchor:'95%'
                        }
                      ]
                    }]
                },{
                  columnWidth:.5,
                  layout:'form',
                  items:[
                    {
                      xtype:'fieldset',
                      title:'维修后走行',
                      width:150,
                      buttonAlign: 'center',
                      autoHeight:true,
                      items:[
                        {
                          xtype:'numberfield',
                          fieldLabel: '镟修后公里数',
                          name: 'xx_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'numberfield',
                          fieldLabel: '探伤后公里数',
                          name: 'ts_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'numberfield',
                          fieldLabel: '二级修后公里',
                          name: 'two_level_fix_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'numberfield',
                          fieldLabel: '三级修后公里',
                          name: 'threex_length',
                          readOnly:false,
                          anchor:'95%'
                        },
                        {
                          xtype:'numberfield',
                          fieldLabel: '四级修后公里',
                          name: 'fourx_length',
                          readOnly:false,
                          anchor:'95%'
                        }]
                    }]
                }
              ]
            }],
          buttons:[{
              text:'确定',
              handler: function(){
                // check form value
                if (editTrainForm.form.isValid()) {
                  editTrainForm.form.submit({
                    method: 'post',
                    waitMsg: '正在更新列车...',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        editTrainWin.destroy();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                editTrainWin.destroy();
              }
            }]
        });
        editTrainForm.form.load({
          url: '/train/edit?id=' + trainId,
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        editTrainForm.render('editTrainForm');
      })
    </script>
  </head>
  <body>
    <div id="editTrainForm"></div>
  </body>
</html>
